import { execSync } from 'child_process';
import { writeFileSync } from 'fs';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';

// 获取当前文件的目录路径
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// 获取 Git Commit Hash
const gitCommit = execSync('git rev-parse --short HEAD').toString().trim();

// 获取当前时间
const buildTime = new Date().toISOString();

// 生成构建信息
const buildInfo = {
  gitCommit,
  buildTime,
};

// 将构建信息写入文件
const outputPath = resolve(__dirname, '../src/build-info.json');
writeFileSync(outputPath, JSON.stringify(buildInfo, null, 2));

console.log('构建信息已注入:', buildInfo);